﻿using KalevaAalto.DataPart.Base;
using MathNet.Numerics.Statistics.Mcmc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;


namespace KalevaAalto.DataPart.DataBasePart
{



    /// <summary>
    /// 利用SqlSugar整合的个人使用的Mysql类
    /// </summary>
    public class Mysql : DataBaseBase
    {

        


        public override SqlSugarClient GetSqlSugarClient()
        {
            return new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = $"server={Localhost};port={Port};user={Username};password={Password}; database={Databasename};",
                DbType = SqlSugar.DbType.MySql,
                IsAutoCloseConnection = true,
            });
        }


        public string Localhost { get; set; } = @"127.0.0.1";
        public int Port { get; set; } = 3306;
        public string Username { get; set; } = @"root";
        public string Password { get; set; } = @"123456";
        public string Databasename { get; set; } = @"mysql";

        public override bool Status
        {
            get
            {
                try
                {


                    // 执行一个简单的查询
                    var version = db.Ado.GetString("SELECT @@VERSION");

                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
        




        public override void Connect()
        {
            
        }

        public override Task ConnectAsync()
        {
            Connect();
            return Task.CompletedTask;
        }

        

        public Mysql() : base()
        { }


        /// <summary>
        /// Mysql常规构造函数
        /// </summary>
        /// <param name="localhost">主机名</param>
        /// <param name="port">端口</param>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="databasename">数据库名称</param>
        public Mysql(string localhost,int port, string username, string password, string databasename) : base()
        {
            Localhost = localhost;
            Port = port;
            Username = username;
            Password = password;
            Databasename = databasename;
            Connect();
        }


        ~Mysql()
        {
            
        }



        


        

        




        




        
    }
}
